<template>
    <el-dialog :title="titleMap[mode]" v-model="visible" :width="500" destroy-on-close @closed="$emit('closed')" :close-on-click-modal="false" :close-on-press-escape="mode != 'show' ? false : true" align-center @submit.prevent @keyup.enter="submit" draggable overflow>
        <el-header>
            {{tip_title}}
        </el-header>
        <el-main>
            <el-form :model="form" :rules="rules" :disabled="mode=='show'" ref="dialogForm">
                <el-form-item label="" prop="font">
                    <el-input v-model="form.font" placeholder="" ref="numberInput"></el-input>
                </el-form-item>
            </el-form>
        </el-main>
        <template #footer>
            <el-button @click="visible = false">取 消</el-button>
            <el-button v-if="mode != 'show'" type="primary" @click="submit">保存</el-button>
        </template>
    </el-dialog>
</template>

<script>

export default {
    emits: ['success', 'closed'],
    data() {
        return {
            mode: "add",
            titleMap: {
                add: '新增加工单',
                edit: '批量设置',
                show: '查看加工单',
            },
            visible: false,
            form: {
                font: "",
            },
            name: "",
            tip_title: "",
            goods_name: "",
            goods_code: "",
            flower: "",
        }
    },
    mounted() {
    },
    methods: {
        //显示
        open(mode = 'add') {
            this.mode = mode;
            this.visible = true;
            return this
        },
        submit() {
            this.visible = false;
            this.$emit('success', this.form, this.name, this.goods_code, this.flower)
        },
        //表单注入数据
        async setData(data,name) {
            if(name == '销售价'){
                this.tip_title = `花型${data.flower}, 数量${data.flower_length}, 请输入销售价`
            }else{
                this.tip_title = `货号${data.goods_code}, 数量${data.goods_code_length}, 请输入销售价`
            }
            this.name = name
            this.goods_name = data.goods_name
            this.goods_code = data.goods_code
            this.flower = data.flower
            setTimeout(()=>{
                this.$nextTick(()=>{
                    this.$refs.numberInput.focus()
                })
            },100)
        },
    }
}
</script>

<style lang="scss" scoped>
.flex{
    display: flex;
    justify-content: space-between;
}
</style>
